import request from "@/util/request"
import { API_SITE } from "./_prefix.js"
const API_PREFIX = "/api/v1/user"

/**
 * 获取客户列表
 */
export const getCustomerByUserIdAndTypeId = (userid, {page = 0, size = 20, keyword, typeId,isBlack}) => {
    return request(`${API_SITE}${API_PREFIX}/${userid}/customer?page=${page || 0}&size=${size || 20}&keyword=${keyword || ""}&typeId=${typeId || ""}&isBlack=${isBlack}`);
}

/**
 * 根据Id查找客户
 */
export const getCustomerById = (userid, customerId) => {
    return request(`${API_SITE}${API_PREFIX}/${userid}/customer/${customerId}`)
}

/**
 * 批量导入客户
 */
export const batchCreate = (userid, typeId, customerDTOList) => {
    return request(`${API_SITE}${API_PREFIX}/${userid}/customer/batch?typeId=${typeId}`,{
        method: "POST",
        body:customerDTOList,
    })
}
/**
 * 创建新客户
 */
export const createNewCustomer = (userid,{typeId, domain, phone, email, websiteTitle, websiteDescription}) => {
    return request(`${API_SITE}${API_PREFIX}/${userid}/customer`,{
        method: "POST",
        body: {
            typeId: typeId,
            domain: domain,
            phone: phone,
            email: email,
            websiteTitle: websiteTitle,
            websiteDescription: websiteDescription
        }
    });
}
/**
 * 删除客户
*/
export const deleteCustomer = (userid,customerId) => {
    return request(`${API_SITE}${API_PREFIX}/${userid}/customer/${customerId}/delete`,{
        method: "POST"
    })
}
/**
 * 编辑客户信息
 */
export const updateCustomerInfo = (userid,customerId,{email,name,domain,typeId,websiteDescription,websiteTitle,phone}) => {
    return request(`${API_SITE}${API_PREFIX}/${userid}/customer/${customerId}`,{
        method: "POST",
        body: {
            email: email,
            name: name,
            domain: domain,
            typeId: typeId,
            websiteDescription: websiteDescription,
            websiteTitle: websiteTitle,
            phone: phone
        }
    })
}

/**
 * 分页获取黑名单客户列表
 */
export const getBlackList = (userid, page = 0, size = 20) => {
    return request(`${API_SITE}${API_PREFIX}/${userid}/customer/black?page=${page}&size=${size}`);
}

/**
 * 拉入黑名单
 */
export const addToBlackList = (userId, customerId) => {
    return request(`${API_SITE}${API_PREFIX}/${userId}/customer/${customerId}/black`,{
        method: "POST"
    });
}

/**
 * 解除黑名单
 */
export const removeFromBlackList = (userId, customerId) => {
    return request(`${API_SITE}${API_PREFIX}/${userId}/customer/${customerId}/unblack`,{
        method: "POST"
    });
}
